<?php
header('Content-type: text/html; charset=utf-8');
//ini_set("register_globals","On");

function NormalizedDate($source) {
	list($f, $s, $t) = explode('-', $source);
	return "$t-$s-$f";
}
function striptitel($titel) {
$vowels = array("/", "\\", " ");
$strip = str_replace($vowels, "-", $titel);
return $strip;
}


function ImageUpload( $varname, $basename, $dest_dir, $i=false, $maxsize=99165536 ) {

	// Determine attribute elements from the uploaded file(s)
	if (is_array($_FILES[$varname]['name'])) {
		$name     = $_FILES[$varname]['name'][$i];
		$type     = $_FILES[$varname]['type'][$i];
		$size     = $_FILES[$varname]['size'][$i];
		$tmp_name = $_FILES[$varname]['tmp_name'][$i];
		$error    = $_FILES[$varname]['error'][$i];
	} else {
		$name     = $_FILES[$varname]['name'];
		$type     = $_FILES[$varname]['type'];
		$size     = $_FILES[$varname]['size'];
		$tmp_name = $_FILES[$varname]['tmp_name'];
		$error    = $_FILES[$varname]['error'];
	}

	if (is_uploaded_file($tmp_name)) {

		if ($size > $maxsize) {
			die("[ImageUpload error]: '" . $name . "' is too big (&gt; $maxsize bytes)");
		}

		switch ($type) {
			case 'image/gif':
				$ext = '.gif';
				break;
			case 'image/jpeg':
			case 'image/pjpeg':
				$ext = '.jpg';
				break;
			default:
				die("[ImageUpload error]: '" . $name . "' is not in GIF or a JPG format.");
		}

		$target = $dest_dir . $basename . $ext;

		// There is probably a bug in PHP 4.2.3 - 4.3.1 running on Win2K platform
		// which causes problems when $target already exist.
		// Work-around: use brute force to hammer the file overwrite mis-protection
		$n = 0;
		while (!@move_uploaded_file($tmp_name, $target) and $n<100) {
			clearstatcache();
			sleep(1);
			$n++;
		}

		return $basename . $ext;

	} // end of if


} // end of function

?>